package jpa4azure.type;

import java.lang.reflect.Field;
import java.util.HashMap;

public class TypeWrapperFactory {

	public static HashMap<Class, TypeWrapper> cache = new HashMap<Class, TypeWrapper>();
	static Jpa4AzureAnnotations helper = new Jpa4AzureAnnotations();

	private static TypeWrapper newwrapper(Class<?> c) {
		TypeWrapper t = new DefaultTypeWrapper(c, helper);
		cache.put(c, t);
		return t;
	}

	public static synchronized TypeWrapper wrap(Class<?> c) {
		return (cache.containsKey(c)) ? cache.get(c) : TypeWrapperFactory
				.newwrapper(c);
	}

	public static TypeWrapper $(Object o) {
		return wrap(o.getClass());
	}

	public static TypeWrapper wrap(Field o) {
		return wrap(o.getType());
	}

	public static TypeWrapper wrap(String s) {
		try {
			return wrap(Class.forName(s));
		} catch (ClassNotFoundException e) {
			Utils.runtime(e);
		}
		return null;
	}


}

